<template>
  <div class="user">
    <!--搜索表单-->
    <div class="common-seach-wrap">
      <el-form
        size="small"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="邀请人信息">
          <el-input
            v-model="formInline.search"
            placeholder="请输入邀请人信息"
          ></el-input>
        </el-form-item>
        <el-form-item label="奖励时间">
          <div class="block">
            <span class="demonstration"></span>
            <el-date-picker
              size="small"
              v-model="formInline.createTime"
              type="daterange"
              value-format="YYYY-MM-DD"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </div>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button type="info" icon="el-icon-back" @click="gotoBack"
            >返回</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-table
          :data="tableData"
          border
          style="width: 100%"
          v-loading="loading"
        >
          <el-table-column
            prop="invitationReceiveId"
            label="活动ID"
          ></el-table-column>
          <el-table-column prop="name" label="活动名称"></el-table-column>
          <el-table-column
            prop="userNickName"
            label="邀请人信息"
          ></el-table-column>
          <el-table-column
            prop="invitationNum"
            label="邀请人数"
          ></el-table-column>
          <el-table-column prop="point" label="奖励积分"></el-table-column>
          <el-table-column prop="coupon" label="奖励优惠券">
            <template #default="scope">
              <div v-if="scope.row.couponList">
                <div
                  class=""
                  v-for="(item, index) in scope.row.couponList"
                  :key="index"
                >
                  <div>
                    <text class="orange">{{ item.name }}</text> x{{
                      item.couponNum
                    }}
                  </div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="balance" label="奖励余额"></el-table-column>
          <el-table-column prop="createTime" label="奖励时间"></el-table-column>
        </el-table>
      </div>
      <!--分页-->
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          :current-page="curPage"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          :total="totalDataNumber"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import InvitationGiftApi from "@/api/invitationgift.js";
export default {
  data() {
    return {
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      formInline: {
        search: "",
        createTime: [],
      },
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getTableList();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },
    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = {};
      Params.pageIndex = self.curPage;
      Params.pageSize = self.pageSize;
      Params.id = self.$route.query.invitation_gift_id;
      Params.search = self.formInline.search;
      Params.type = 0;
      Params.startDate = self.formInline.createTime[0];
      Params.endDate = self.formInline.createTime[1];
      InvitationGiftApi.receivelist(Params, true)
        .then((res) => {
          self.loading = false;
          self.tableData = res.data.records;
          self.totalDataNumber = res.data.total;
        })
        .catch((error) => {
          self.loading = false;
        });
    },
    /*搜索查询*/
    onSubmit() {
      let self = this;
      self.loading = true;
      self.getTableList();
    },
    /*返回上一页面*/
    gotoBack() {
      this.$router.back(-1);
    },
  },
};
</script>
<style></style>
